//
//  huodongTableViewController.m
//  PASystem
//
//  Created by michael on 16/8/4.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "huodongTableViewController.h"

@interface huodongTableViewController ()
@property(nonatomic,assign)int currentPage; //当前页
@property(nonatomic,strong)NSMutableArray * dataArray;
@property(nonatomic,strong)NSDictionary * dic;
@property(nonatomic,assign)int totalCounts; //总条数
@end

@implementation huodongTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];


     self.title = _string;
    self.view.backgroundColor = [UIColor whiteColor];
            [self loadData]; //加载网络数据
self.tableView.bounces = NO;


}
- (void)viewDidAppear:(BOOL)animated
{
self.tableView.frame = CGRectMake(0, 64, KScreenWidth, KScreenHeight-46-64);
     UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
    
    self.tableView.layer.borderWidth = 10;
    self.tableView.layer.borderColor = [myColor CGColor];

}
-(NSMutableArray*)dataArray{
    if (_dataArray == nil) {
      _dataArray =   [NSMutableArray array];
    }
    return _dataArray;
}
#pragma mark 加载网络数据
-(void)loadData{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':%@,'service': %@, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",_action,_service,userId,pwdId,userHumber,_id];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

       
     NSDictionary *dic = JSON[@"reason"];
        
    NSDictionary *dict = dic[@"attrs"];
//    NSLog(@"%@",dict);
    
    _dic = dict;
    [_dataArray addObject:dict];
    

//     NSLog(@"11%@",_dataArray);
        
        [self.tableView reloadData];
       
    } failure:^(NSError *error) {
        
    }];
 
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  11;
}
#pragma mark UITableView dataScource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row ==0) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, cell.contentView.height)];
    label.text = @"活动主题:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -100, label.height)];
    label2.text = _dic[@"WSNAME"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}
    if (indexPath.row ==1) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"接待机构名称:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth -120, label.height)];
      label2.textAlignment = NSTextAlignmentRight;

    label2.text = _dic[@"JGNAME"];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}
if (indexPath.row ==2) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"活动人数:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -120, label.height)];
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"RECEPTNUM"]];
      label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}
if (indexPath.row ==3) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"联系人:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth  -120, label.height)];
    label2.text = _dic[@"LINKMAN"];
          label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==4) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"联系电话:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, label.height)];
      label2.text = [NSString stringWithFormat:@"%@",_dic[@"PHONE"]];
      label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==5) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"活动地点:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, label.height)];
    label2.text = _dic[@"RECEPTADDR"];
          label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==6) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"活动时间:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, label.height)];
  //时间
  NSString *string = _dic[@"RECEPTTIME"];
  NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
 fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
     NSDate *date = [fmt dateFromString:string];
     NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.dateFormat = @"yyyy-MM-dd";
     NSString *selfYear = [fm stringFromDate:date];
      label2.textAlignment = NSTextAlignmentRight;

  
    label2.text = selfYear;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==7) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"我方接待人:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, label.height)];
    label2.text = _dic[@"RECEIVER"];
          label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==8) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 120, cell.contentView.height)];
    label.text = @"我方接待人电话:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth -140, label.height)];
        label2.text = [NSString stringWithFormat:@"%@",_dic[@"RECEPTPHONE"]];

      label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}if (indexPath.row ==9) {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
            CGFloat titleSize = [OAToolBox sizebyText:_dic[@"CONTENT"] font:14 minsWidth:120];
  if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}
    label.text = @"工作内容:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, titleSize)];
    label2.text = _dic[@"CONTENT"];
    label2.numberOfLines = 0;
          label2.textAlignment = NSTextAlignmentRight;

     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;

}else {
    
     UITableViewCell* cell = [[UITableViewCell alloc]init];
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    
    label.text = @"活动成果:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
     CGFloat titleSize = [OAToolBox sizebyText:_dic[@"RESULTS"] font:12 minsWidth:120];

      if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}
  UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth  -120, titleSize)];
    label2.text = _dic[@"RESULTS"];
          label2.textAlignment = NSTextAlignmentRight;
label2.numberOfLines = 0;
//label2.backgroundColor = [UIColor redColor];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;


}
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat H = 44;
if (indexPath.row == 9){
 CGFloat titleSize = [OAToolBox sizebyText:_dic[@"CONTENT"] font:12 minsWidth:120];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}

else if (indexPath.row ==10){
 CGFloat titleSize = [OAToolBox sizebyText:_dic[@"RESULTS"] font:12 minsWidth: 120];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}
else{

return H;
}

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
